package com.tjetc.controller;
import com.github.pagehelper.PageInfo;
import com.tjetc.domain.SpecializedGroup;
import com.tjetc.service.SpecializedGroupService;
import com.tjetc.service.impl.SpecializedGroupServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (specialized_group)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/specialized_group")
public class SpecializedGroupController {
/**
* 服务对象
*/
@Resource
private SpecializedGroupService specializedGroupService;

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public SpecializedGroup selectOne(@RequestParam("id") Integer id) {
return specializedGroupService.selectByPrimaryKey(id);
}
@GetMapping("selAll")
    public List<SpecializedGroup> selAll(@RequestParam("name")String name) {
    System.out.println("name = " + name);
    return specializedGroupService.selectByName(name);
}
@GetMapping("selAllspecialgroup")
    public Result selAllspecialgroup() {
    return specializedGroupService.selectAll();
}
@GetMapping("getByNameAndPage")
    public PageInfo<SpecializedGroup> getByNameandPage(@RequestParam("name")String name, @RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize) {
    return specializedGroupService.getByNameandPage(name,pageNum,pageSize);
}
//用于添加和修改  save
    @RequestMapping("save")
    public Result save(@RequestBody SpecializedGroup specializedGroup){
    specializedGroup.setDId(specializedGroup.getDepartment().getId());
        return  specializedGroupService.save(specializedGroup);
    }
    @RequestMapping("del")
    public Result del(@RequestParam("id") Integer id){
        return  specializedGroupService.deleteByPrimaryKey(id)==0?Result.fail("删除失败"):Result.ok();
    }

}

